package com.qf.news.controller;

import com.qf.news.domain.Luoyanguser;
import com.qf.news.response.Response;
import com.qf.news.service.LuoyanguserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("Luoyanguser")
@RequiredArgsConstructor
public class LuoyanguserController {
    private final LuoyanguserService luoyanguserService;
    @PostMapping("/luoyanguserLogin")
    public Response<Luoyanguser> luoyanguserLogin(@RequestBody Luoyanguser luoyanguser) {
        Luoyanguser luoyanguserLogin = luoyanguserService.luoyanguserLogin(luoyanguser.getUsername(), luoyanguser.getPassword());
        if (Objects.nonNull(luoyanguserLogin)) {
            System.out.println("成功");
            return Response.success(luoyanguserLogin);

        } else {
            System.out.println("失败");
            return Response.fail(null);
        }
    }
    @PostMapping("addNews")
    public Response<Luoyanguser> addLuoyanguser(@RequestBody Luoyanguser luoyanguser) {
        luoyanguserService.addLuoyanguser(luoyanguser);
        return Response.success(luoyanguser);
    }

}
